*****************FULL SAMPLE***********************

ssc install reghdfe
ssc install ftools

use anon t ev w1 kor ferfi  wh1 vallazon* feor1_h2 if kor>=18 & kor<=70  & vallazon1~=.  using "$in/admin3_alap.dta" , clear

rename vallazon1 vallazon
merge m:1 vallazon ev using "$in/admin3_nav_eredeti.dta", nogen keep(master match) keepusing(letszam)

set more off
gen min_w=50000 if ev==2003
replace min_w=53000 if ev==2004
replace min_w=57000 if ev==2005
replace min_w=62500 if ev==2006
replace min_w=65500 if ev==2007
replace min_w=69000 if ev==2008
replace min_w=71500 if ev==2009
replace min_w=73500 if ev==2010
replace min_w=78000 if ev==2011
replace min_w=93000 if ev==2012
replace min_w=98000 if ev==2013
replace min_w=101500 if ev==2014
replace min_w=105000 if ev==2015
replace min_w=111000 if ev==2016
replace min_w=127500 if ev==2017

keep if wh1==40

keep if w1>=0 & w1~=.

collapse (mean)  w1 (last)  kor , by(vallazon ev anon)

gen age2=(kor-40)^2
gen age3=(kor-40)^3
 
gen lnw=ln(w1)

	set more off, perm 
	cap drop conseed
	gen conseed=0
	replace conseed=1 if anon==192047

	forval i=1/10 {
	bysort anon (vallazon ev): egen conn=max(conseed)
	replace conseed=conn
	drop conn
	bysort vallazon (anon ev): egen conn=max(conseed)
	replace conseed=conn
	drop conn
	disp(`i')
	}

	tab conseed 

	
global controls "c.age2 c.age3 i.ev "
drop if conseed==0

reghdfe lnw $controls if conseed==1, absorb (fei=anon fej=vallazon , savefe)

save "$out_AKM/FEi_temp.dta", replace
save "$out_AKM/FEj_temp.dta", replace

use "$out_AKM/FEi_temp.dta", clear
rename fei anon_fix
keep anon anon_fix
duplicates drop
drop if anon_fix==.
compress
save "$out_AKM/FEi_full_Jan2023.dta", replace

use "$out_AKM/FEj_temp.dta", clear
rename fej vall_fix
keep vallazon vall_fix
duplicates drop
drop if vall_fix==.
compress
save "$out_AKM/FEj_full_Jan2023.dta", replace

